package com.senjoeson.baselib_ui.base

import android.graphics.Color
import android.support.design.widget.TabLayout
import android.support.v4.app.Fragment
import android.support.v4.view.ViewPager
import com.senjoeson.baselib_ui.R
import com.senjoeson.baselib_ui.adapter.MyPagerAdapter


abstract class BaseBottomTabActivity : BaseToolbarActivity() {



    var mViewPager: ViewPager? = null
    var tablayout: TabLayout? = null


    override fun initView() {
        mViewPager = findViewById(R.id.viewpager)
        tablayout = findViewById(R.id.tablayout)
        val myAdapter = MyPagerAdapter(supportFragmentManager)
        myAdapter.setTilte(getTabTitles())
        val fragments = arrayListOf<Fragment>()
        myAdapter.setFragments(initFragments(fragments))

        mViewPager?.adapter = myAdapter
        tablayout?.setTabTextColors(Color.GRAY, Color.WHITE)
        tablayout?.setupWithViewPager(mViewPager)

    }



    abstract fun initFragments(fragments: ArrayList<Fragment>): MutableList<Fragment>


    abstract fun getTabTitles(): Array<String>

    override fun onBackArrowEvent() {
        //set the left arrow event
        onBackPressed()
    }


    override fun setMainTitle(): String {
        return javaClass.simpleName
    }


}
